<template>
  <div>
    <el-form :inline="true">
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="transactTime"
          type="date"
          placeholder="选择日期"
        />
        <span>至</span>
        <el-date-picker
          v-model="transactTimeEnd"
          type="date"
          placeholder="选择日期"
        />
      </el-form-item>
      <el-form-item label="处理人">
        <el-input v-model="ownerName" clearable />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getData">查询</el-button>
    </el-form>
    <lb-table
      ref="lbTable"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      @fetch="getData"
    />
  </div>
</template>

<script>
  import { fromPlatColMap } from '@/utils/map'
  import { parseTime } from '@/utils'
  import { customerCustomerorder } from '@/api'

  export default {
    name: 'tab-history',
    props: ['csmId'],
    data() {
      return {
        transactTime: '',
        transactTimeEnd: '',
        ownerName: '',
        tableData: {
          column: [

            { label: '订单号', prop: 'orderCode', width: 100 },
            { label: '订单来源', prop: 'fromPlat', width: 100, align: 'center',
              render: (h, { row }) => <span>{ row.fromPlat && fromPlatColMap[row.fromPlat] }</span>
            },
            { label: '处理人', prop: 'ownerName', width: 100, align: 'center' },
            { label: '联系人', prop: 'contact', width: 100, align: 'center' },
            { label: '联系电话', prop: 'contactPhone', width: 120, align: 'center' },
            { label: '送气地址', prop: 'csmAddress', width: 250, align: 'left' },
            { label: '商品描述', prop: 'goodsDesc', width: 180 },
            { label: '商品数量', prop: 'goodsCount', width: 80, align: 'right' },
            { label: '下单时间', prop: 'transactTime', width: '', align: 'center',
              render: (h, { row }) => <span>{ row.transactTime && parseTime(row.transactTime, '{y}-{m}-{d} {h}:{i}:{s}') }</span>
            },
            { label: '实收金额', prop: 'taccReceivable', width: 80, align: 'center' }
          ],
          data: []
        }
      }
    },
    methods: {
      async getData({ currentPage = 1, pageSize = 20 }) {
        const params = {
          currentPage,
          pageSize,
          csmId: String(this.csmId),
          'orderStatus': 10,
          'transactTime': this.transactTime,
          'transactTimeEnd': this.transactTimeEnd,
          'ownerName': this.ownerName
        }
        const res = await customerCustomerorder(params)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      }
    }
  }
</script>

<style scoped>

</style>
